package com.whitlock.backend.controller;

import com.whitlock.backend.entity.TKPermission;
import com.whitlock.backend.service.PermisssionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Whitlock
 * @date 2020/7/14   2:29 下午
 */

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    PermisssionService permisssionService;
    /**
     * 根据用户id获取右侧菜单权限
     * @param userId
     * @return
     */
    @RequestMapping("/getPermissionByUserId/{userId}")
    @RequiresPermissions("sys:menu:base")
    public List<TKPermission> getPermissionByUserId(@PathVariable String userId){
        return permisssionService.list().stream().filter(tkPermission -> !StringUtils.isEmpty(tkPermission.getPermissionName())).collect(Collectors.toList());
    }
}
